package com.luocj.looook.activity;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;

import com.luocj.looook.R;
import com.luocj.looook.base.BaseActivity;

public class WebViewActivity extends BaseActivity {

    private static final String TAG = WebViewActivity.class.getSimpleName();
    public static final String DATA_URL = "DATA_URL";
    private WebView mWebView;
    private ProgressBar mProgressBar;
    private static final int MAX_VALUE = 100;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_web_view;
    }

    @Override
    protected void initView() {
        mWebView = (WebView) findViewById(R.id.webview);
        mProgressBar = (ProgressBar) findViewById(R.id.pb_progress);
        WebSettings settings = mWebView.getSettings();//用来设置webview的属性
        settings.setBuiltInZoomControls(true);
        settings.setJavaScriptEnabled(true);

    }

    private WebChromeClient mWebChromeClient = new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            mProgressBar.setProgress(newProgress);//加载过程中更新进度
            if (newProgress == MAX_VALUE) {
                mProgressBar.setVisibility(View.GONE);
            }
            super.onProgressChanged(view, newProgress);
        }
    };

    @Override
    protected void initData() {
        String dataUrl = (String) getIntent().getSerializableExtra(WebViewActivity.DATA_URL);
        mProgressBar.setMax(MAX_VALUE);
        mWebView.loadUrl(dataUrl);
        mWebView.setWebChromeClient(mWebChromeClient);
    }
}
